<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dung
 * Date: 2/19/14
 * Time: 12:07 AM
 * To change this template use File | Settings | File Templates.
 */
?>
<?php
if(isset($_SESSION["users_id"]) && $_SESSION["group_id"]==1){
    if(isset($_POST["btnAdd"]))
    {
        $name=$_POST["name"];
        $image=$_POST["Image"];
        $detail=$_POST["Content"];
        $language_id=$_POST["language"];settype($language_id,"int");
        AddEmployee($name,$image,$detail,$language_id);
        header("location:index.php?p=employeelist");
    }
?>
<form id="maincp" name="form1" method="post" action="">
    <h1 class="h1">Add Employee</h1>
    <p>Please complete all form below to add a new employee.</p>
    <ul class="list2">
        <li><h3>Name</h3></li>
        <li><input class="input" type="text" name="name" id="name" /></li>
        <li><h3>Avatar</h3></li>
        <li><input class="input twocol" type="text" name="Image" id="Image" />
            <input class="twocol2" onclick="BrowseServer('','Image')" type="button" name="btnChonFile" id="btnChonFile" value="Browse" />
        </li>
        <li><h3>Info</h3></li>
        <li><textarea class="ckeditor" name="Content" id="Content" cols="45" rows="5"></textarea></li>
        <li>
            <fieldset>
                <legend><h3>Language</h3></legend>
                <p>Choose contents language.</p>
                <select id="language" name="language" style="width: 100px">
                    <?php
                    $language=LanguageList();
                    while($row_language=mysql_fetch_array($language)){ ?>
                        <option value="<?php echo $row_language['language_id']; ?>"><?php echo $row_language['name']; ?></option>
                    <?php } ?>
                </select>
            </fieldset>
        </li>
        <li><input class="button addnews" type="submit" name="btnAdd" id="btnAdd" value="Add Employee" /></li>
    </ul>
    <a href="index.php?p=cpanel" title="Back to Dashboard">&laquo; Back to Dashboard.</a>
</form>

    <script type="text/javascript">
        function BrowseServer(startupPath, functionData) {
            var finder = new CKFinder();
            finder.basePath = 'js/ckfinder/';
            //???ng path n?i ??t ckfinder
            finder.startupPath = startupPath;
            //???ng path hi?n s?n cho user ch?n file
            finder.selectActionFunction = SetFileField;
            // hàm s? ???c g?i khi 1 file ???c ch?n
            finder.selectActionData = functionData;
            //id c?a text field c?n hi?n ??a ch? hình
            //finder.selectThumbnailActionFunction = ShowThumbnails; //hàm s? ???c g?i khi 1 file thumnail ???c ch?n
            finder.popup();
            // B?t c?a s? CKFinder
        }//BrowseServer

        function SetFileField(fileUrl, data) {
            document.getElementById(data["selectActionData"]).value = fileUrl;
        }

        function ShowThumbnails(fileUrl, data) {
            var sFileName = this.getSelectedFile().name;
            // this = CKFinderAPI
            document.getElementById('thumbnails').innerHTML += '<div class="thumb">' + '<img src="' + fileUrl + '" />' + '<div class="caption">' + '<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' + '</div>' + '</div>';
            document.getElementById('preview').style.display = "";
            return false;
            // n?u là true thì ckfinder s? t? ?óng l?i khi 1 file thumnail ???c ch?n
        }
    </script>

<?php
}else{
    header("location:index.php?p=logincp");
}
?>